﻿using Flurl.Http;
using Flurl.Http.Configuration;
using MXERP.Shared.Constants;
using MXERP.Shared.Wrapper;

namespace MXERP.Infrastructure.Managers
{
    public class RoleManager : IRoleManager
    {
        private readonly IFlurlClient _flurlClient;
        public RoleManager(IFlurlClientCache clients)
        {
            _flurlClient = clients.Get(ApiConstant.MXERP);
        }

        public async Task<ApiResponse<List<RoleResponse>>> GetBasicRoles(long[] ids)
        {
            var result = await _flurlClient.Request(EndpointConstant.Role.GetBasicRoles).SetQueryParams(new { Ids = ids }).GetAsync().ReceiveJson<ApiResponse<List<RoleResponse>>>();
            return result;
        }

        public async Task<ApiResponse<PageResponse<RoleResponse>>> Query(PageRequest<RoleRequest> request)
        {
            var result = await _flurlClient.Request(EndpointConstant.Role.Query).PostJsonAsync(request).ReceiveJson<ApiResponse<PageResponse<RoleResponse>>>();
            return result;
        }

        public async Task<ApiResponse<RoleResponse>> Detail(long id)
        {
            var result = await _flurlClient.Request(EndpointConstant.Role.Detail).SetQueryParams(new { Id = id }).GetAsync().ReceiveJson<ApiResponse<RoleResponse>>();
            return result;
        }

        public async Task Save(RoleResponse request)
        {
            await _flurlClient.Request(EndpointConstant.Role.Save).PostJsonAsync(request);
        }

        public async Task Remove(long[] ids)
        {
            await _flurlClient.Request(EndpointConstant.Role.Remove).SetQueryParams(new { Ids = ids }).GetAsync();
        }
    }
}
